﻿using System;
using System.IO;
using System.Reflection;
using SF.Code.Extension.AssemblyHelper;
using SF.Code.Extension.ComputerLanguages;
using SG.Lang.Dry.Base;
using SG.Lang.Dry.Code;
using SG.Lang.Dry.Mirrors;
using SG.Lang.Dry.Persistance;

namespace SG.Lang.Dry.Controlling
{
    public static class Importer
    {
        public static VirtualAssembly Import(this Assembly assembly)
        {
            var lastWriteTimeUtc = File.GetLastWriteTimeUtc(assembly.Location);
            var guid = assembly.GetGuid();
            var elementRecord = new ElementRecord(ref guid, ElementKind.Assembly, lastWriteTimeUtc);

            var types = assembly.GetExportedTypes();
            var items = types.ConvertAndSave(lastWriteTimeUtc, TypeRef.Create);

            return new VirtualAssembly(ref elementRecord, items);
        }
    }
}
